import { request } from '@/api/request';
import { HttpMethod } from '@/services/types';

/**
 * GET /user/sales 获取商家销量榜单
 * @param options
 */
export async function resUserSales(
  options?: { [key: string]: any },
) {
  return request<API.UserSales[]>('/user/sales', {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * GET /user 用户信息
 * @param options
 */
export async function resUserinfo(
  options?: { [key: string]: any },
) {
  return request<API.Userinfo>('/user', {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

/**
 * PUT /user 修改用户信息
 * @param params
 * @param options
 */
export async function resChangeUserinfo(
  params: API.ChangeUserinfoParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/user', {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /user/avatar 修改头像
 * @param params
 * @param options
 */
export async function resChangeAvatar(
  params: API.ChangeAvatarParams,
  options?: { [key: string]: any },
) {
  return request<R<string>>('/user/avatar', {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}

/**
 * GET /user/:id 获取用户详情
 * @param id
 * @param options
 */
export async function resUserinfoAdmin(
  id: number,
  options?: { [key: string]: any },
) {
  return request<API.Userinfo>('/user/' + id, {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}

 /*              admin                */

/**
 * PUT /admin/user/:id 修改用户信息
 * @param id
 * @param params
 * @param options
 */
export async function resChangeUserInfoAdmin(
  id: number,
  params: API.ChangeUserInfoAdminParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/user/' + id, {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /admin/user/lock/:id 禁用和启用
 * @param id
 * @param options
 */
export async function resLockUserAdmin(
  id: number,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/user/lock/' + id, {
    method: HttpMethod.PATCH,
    ...(options || {}),
  });
}

/**
 * POST /admin/user 添加用户
 * @param params
 * @param options
 */
export async function resAddUserAdmin(
  params: API.AddUserAdminParams ,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/admin/user', {
    method: HttpMethod.POST,
    data:params,
    ...(options || {}),
  });
}

/**
 * GET /admin/user 用户列表
 * @param params
 * @param options
 */
export async function resUserListAdmin(
  params: API.UserListAdminParams ,
  options?: { [key: string]: any },
) {
  return request<API.PaginationResult<API.Userinfo>>('/admin/user', {
    method: HttpMethod.GET,
    params,
    ...(options || {}),
  });
}